package com.selenium.cases;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import com.selenium.base.DriverBase;

public class TestCourseList extends BaseCase{
	
	DriverBase driver;
	
	public TestCourseList() {
		this.driver = this.InitDriver("chrome");
		this.driver.maxWindows();
	}
	@Test
	public void courseList() {
		this.driver.get("https://www.imooc.com/course/list");
		for (String e:this.courseListString()) {
			this.driver.findElement(By.xpath("//p[contains(text(),'"+e+"')]/..")).click();
			//this.driver.back();
		}
	}
	
	public List<String> courseListString(){
		List<String> list = new ArrayList<String>();
		WebElement table = this.driver.findElement(By.className("moco-course-list"));
		List<WebElement> listElement = table.findElements(By.className("course-card-content"));
		for (WebElement e: listElement) {
			list.add(e.findElement(By.className("course-card-desc")).getText());
		}
		
		return list;
	} 
	
	
	public void back() {
		this.driver.back();
	}

}
